package cn.gemiman.daoyi.module.netty.server.mqtt.listener;

import cn.gemiman.daoyi.module.netty.server.mqtt.options.ClientSession;
import cn.gemiman.daoyi.module.netty.server.mqtt.options.CustomMqttPublishMessage;
import cn.gemiman.daoyi.module.netty.server.mqtt.options.IMqttMessageListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.function.Function;

@Slf4j
@Component
public class MqttMessageListenerImpl implements IMqttMessageListener {
    @Override
    public void offline(String uuid, ClientSession clientSession) {

    }

    @Override
    public void onMessage(String ip, String channelId, String topic, String message, Function<CustomMqttPublishMessage, Boolean> publisher) {
        log.info("{}:{}", topic, message);
        publisher.apply(new CustomMqttPublishMessage(channelId, topic + "_reply", message));
    }

    @Override
    public void online(String uuid, ClientSession clientSession) {

    }

    @Override
    public String clientIdToUuid(String clientId) {
        return "";
    }
}
